/*
 * Copyright 2018 Youchaoshi authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package common.tool;

import android.support.design.widget.Snackbar;
import android.view.View;


/**
 * SnackBar的实现方式其实是addView，因此，它的父控件不能是ScrollView这样只允许有一个子控件的控件。
 * SnackBar.show()的时候,要注意先把Keyboard.hide()了。不然,键盘就会遮住SnackBar。
 */
public class SnackBarUtil {

    public static volatile int count = 0;
    public static synchronized void show(View view, String message){
        Snackbar.make(view,message,Snackbar.LENGTH_SHORT).show();
        count ++ ;
        gc();
    }

//    public static void showMsg(View view,String msg){
//        show(view,msg);
//    }

    private static synchronized void gc() {
        if(count > 10){
            System.gc();
            count = 0;
        }
    }
}
